package com.tianji.learning.controller;


import com.tianji.common.domain.R;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.domain.vo.LearningPlanVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author waker
 * @since 2025-10-18
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    /**
     * 2. 分页查询我的课表
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> PageQueryMyLessons(PageQuery pageQuery){
        return lessonService.PageQueryMyLessons(pageQuery);
    }

    /**
     * 3. 查询当前正在学习的课程
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson(){
        return lessonService.queryMyCurrentLesson();
    }

    /**
     * 4. 用户删除课程
     * @param courseId
     * @return
     */
    @ApiOperation("用户删除课程")
    @DeleteMapping("/{courseId}")
    public void deleteMyLesson(@PathVariable("courseId") Long courseId){
        lessonService.deleteMyLesson(courseId);
    }


    /**
     * 5. 检查课程是否有效
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("检查课程是否有效")
    Long isLessonValid(@PathVariable("courseId") Long courseId){
        return lessonService.isLessonValid(courseId);
    }

    /**
     * 6. 根据id查询用户课表中指定课程的状态
     * @return
     */
    @GetMapping("/{courseId}")
    public LearningLessonVO getCourseStatusById(@PathVariable("courseId") Long courseId){
        return lessonService.getCourseStatusById(courseId);
    }

    /**
     * 7. 统计课程的学习人数
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/count")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 8. 创建或修改学习计划 (day03 3)
     * @param learningPlanDTO
     */
    @ApiOperation("创建或修改学习计划")
    @PostMapping("/plans")
    public void createPlans(@RequestBody LearningPlanDTO learningPlanDTO){
        lessonService.createPlans(learningPlanDTO);
    }

    /**
     * 9. 分页查询我的学习计划 (day03 4)
     * @param pageQuery
     * @return
     */
    @ApiOperation("分页查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return lessonService.queryMyPlans(pageQuery);
    }
}
